Skip to content

feat: add new TupleViewer component#1236

Open
aaguiarz wants to merge 5 commits intomainfrom
feat/tuple-viewer
Open

feat: add new TupleViewer component#1236
aaguiarz wants to merge 5 commits intomainfrom
feat/tuple-viewer

Conversation

@aaguiarz
Copy link
Copy Markdown
Member

@aaguiarz aaguiarz commented Apr 12, 2026

Description

What problem is being solved?

Create a component to display tuples. Currently we explain the tuples we need by describing them in YAML format or with Write() Request Viewer. Let's tweak the visual style cc @dongniwang @ttrzeng .

I did it with a 2 column layout, which complicated things, e.g. we can't use the standard CodeBlock. We can re-evaluate it, but according to Claude even if we do that, we won't be able to get what we are getting in terms of formatting.

How is it being solved?

Before:

image

After

image

What changes are made to solve it?

References

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • Documentation

    • Updated task-based authorization guide with improved relationship tuple presentation and visualization.
  • New Features

    • Added interactive TupleViewer component to documentation featuring syntax-highlighted tuples, copy-to-clipboard support, and side-by-side comparison view.

@aaguiarz aaguiarz requested review from a team as code owners April 12, 2026 03:51
Copilot AI review requested due to automatic review settings April 12, 2026 03:51
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 12, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 61a639f1-7d15-472e-b1fd-873d6f2062b0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR introduces a new TupleViewer React component that renders OpenFGA relationship tuples with support for side-by-side display and clipboard copy functionality. The component is integrated into the task-based authorization documentation guide, replacing inline YAML tuple examples.

Changes

Cohort / File(s) Summary
TupleViewer Component
src/components/Docs/SnippetViewer/TupleViewer.tsx, src/components/Docs/SnippetViewer/index.ts
New React component that renders OpenFGA relationship tuples with optional conditions, supports 2-column grid layout for side-by-side display via rightColumnTuples, generates YAML representation, and includes clipboard copy functionality with state tracking and auto-reset timeout.
Documentation Updates
docs/content/modeling/agents/task-based-authorization.mdx
Replaced multiple inline YAML tuple examples with <TupleViewer> component instances across sections (tool authorization, session/agent scoping, expiration/call-count conditions, agent binding). Reformatted condition examples into condition: { name, context } object structure and split examples into tuples and optional rightColumnTuples props.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add new TupleViewer component' is clear, specific, and accurately describes the main change: introducing a new React component for displaying tuples.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/tuple-viewer

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 12, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://openfga.github.io/openfga.dev/pr-preview/pr-1236/

Built to branch gh-pages at 2026-04-12 19:35 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new TupleViewer React component to render OpenFGA relationship tuples in a styled, copyable block, and updates the “Task-Based Authorization” agent modeling guide to use it instead of inline YAML snippets.

Changes:

  • Introduced TupleViewer component (including a custom copy-to-clipboard YAML formatter and optional two-column layout).
  • Re-exported TupleViewer via the SnippetViewer barrel so it’s available from @components/Docs.
  • Replaced several YAML code fences in task-based-authorization.mdx with <TupleViewer ... /> usages.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
src/components/Docs/SnippetViewer/TupleViewer.tsx New tuple rendering + YAML copy button implementation.
src/components/Docs/SnippetViewer/index.ts Re-export of the new component.
docs/content/modeling/agents/task-based-authorization.mdx Swaps YAML examples to the new visual TupleViewer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/components/Docs/SnippetViewer/TupleViewer.tsx Outdated
Comment thread src/components/Docs/SnippetViewer/TupleViewer.tsx Outdated
Comment thread src/components/Docs/SnippetViewer/TupleViewer.tsx Outdated
Comment thread src/components/Docs/SnippetViewer/TupleViewer.tsx Outdated
Comment thread src/components/Docs/SnippetViewer/TupleViewer.tsx Outdated
Comment thread docs/content/modeling/agents/task-based-authorization.mdx
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/components/Docs/SnippetViewer/TupleViewer.tsx (1)

220-221: Prefer non-empty check for right-column rendering.

Line 220 and Line 245 treat rightColumnTuples as truthy. Passing [] renders an empty second column. Consider checking .length > 0 instead.

💡 Proposed fix
 export function TupleViewer({ tuples, rightColumnTuples }: TupleViewerProps): JSX.Element {
   const { plain } = usePrismTheme();
-  const allTuples = rightColumnTuples ? [...tuples, ...rightColumnTuples] : tuples;
+  const hasRightColumn = (rightColumnTuples?.length ?? 0) > 0;
+  const allTuples = hasRightColumn ? [...tuples, ...rightColumnTuples!] : tuples;
   const yaml = allTuples.map(formatYaml).join('\n');
@@
-        {rightColumnTuples ? (
+        {hasRightColumn ? (
           <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '0 2ch' }}>

Also applies to: 245-246

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/Docs/SnippetViewer/TupleViewer.tsx` around lines 220 - 221,
The code currently treats rightColumnTuples as truthy which allows an empty
array to trigger a second (empty) column; change both the allTuples construction
and the second-column render condition to explicitly check
rightColumnTuples.length > 0 (i.e., use rightColumnTuples &&
rightColumnTuples.length > 0) so allTuples = rightColumnTuples &&
rightColumnTuples.length > 0 ? [...tuples, ...rightColumnTuples] : tuples and
render the right column only when rightColumnTuples.length > 0 inside the
TupleViewer component where rightColumnTuples and formatYaml are used.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/components/Docs/SnippetViewer/TupleViewer.tsx`:
- Around line 126-132: The YAML builder in formatYaml currently interpolates
tuple.user, tuple.relation, tuple.object, and tuple.condition.name as raw
strings which can break YAML; update formatYaml to pass these values through the
same value formatter used for context values (the project's existing "value
formatter" function) before interpolating so top-level scalars are
quoted/escaped correctly—replace direct uses of tuple.user, tuple.relation,
tuple.object and tuple.condition.name with calls to that formatter and adjust
the pushed lines to use the formatted results.

---

Nitpick comments:
In `@src/components/Docs/SnippetViewer/TupleViewer.tsx`:
- Around line 220-221: The code currently treats rightColumnTuples as truthy
which allows an empty array to trigger a second (empty) column; change both the
allTuples construction and the second-column render condition to explicitly
check rightColumnTuples.length > 0 (i.e., use rightColumnTuples &&
rightColumnTuples.length > 0) so allTuples = rightColumnTuples &&
rightColumnTuples.length > 0 ? [...tuples, ...rightColumnTuples] : tuples and
render the right column only when rightColumnTuples.length > 0 inside the
TupleViewer component where rightColumnTuples and formatYaml are used.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ced84891-0dc0-4219-b8c2-932a4dc231f4

📥 Commits

Reviewing files that changed from the base of the PR and between 671d560 and 1933469.

📒 Files selected for processing (3)
  • docs/content/modeling/agents/task-based-authorization.mdx
  • src/components/Docs/SnippetViewer/TupleViewer.tsx
  • src/components/Docs/SnippetViewer/index.ts

Comment thread src/components/Docs/SnippetViewer/TupleViewer.tsx
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new docs UI component to render OpenFGA relationship tuples with a more structured, readable layout, and updates the task-based authorization agent guide to use it instead of inline YAML blocks.

Changes:

  • Introduces TupleViewer React component with optional two-column tuple rendering and a copy-to-clipboard action.
  • Adds global styling for the tuple viewer, including responsive single-column behavior on mobile.
  • Updates task-based-authorization.mdx to render tuple examples via TupleViewer.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/css/custom.css Adds styling hooks and responsive layout rules for the new tuple viewer component.
src/components/Docs/SnippetViewer/TupleViewer.tsx Implements the new TupleViewer component, tuple formatting, and copy button behavior.
src/components/Docs/SnippetViewer/index.ts Exports TupleViewer from the SnippetViewer barrel for downstream imports.
docs/content/modeling/agents/task-based-authorization.mdx Replaces YAML tuple snippets with TupleViewer usage for improved presentation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +11 to +14
import { CodeBlockContextProvider, createCodeBlockMetadata } from '@docusaurus/theme-common/internal';
import CopyButton from '@theme/CodeBlock/Buttons/CopyButton';
import type { RelationshipCondition } from '../RelationshipTuples/Viewer';

}

function formatDisplayValue(value: unknown): string {
return typeof value === 'string' ? value : JSON.stringify(value);
Comment on lines +124 to +139
function formatYaml(tuple: Tuple): string {
const lines = [`- user: ${tuple.user}`, ` relation: ${tuple.relation}`, ` object: ${tuple.object}`];

if (tuple.condition) {
lines.push(` condition:`);
lines.push(` name: ${tuple.condition.name}`);

const contextEntries = Object.entries(tuple.condition.context ?? {});
if (contextEntries.length > 0) {
lines.push(` context:`);
}

for (const [key, value] of contextEntries) {
lines.push(` ${key}: ${formatYamlValue(value)}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants